import {createI18n} from "vue-i18n";
import {default as zh, item as zh_item} from './zh-cn.js';
import {default as en, item as en_item} from './en.js';


export const language = (
  navigator.language || navigator.userLanguage || 'zh-CN'
).toLowerCase();

export default createI18n({
  fallbackLocale: 'zh-CN',
  locale: language,
  globalInjection: true,
  legacy: false,
  messages: {
    zh, 'zh-cn': zh, en, 'en-US': en
  }
});

export const list = [
  zh_item, en_item
];

const map = {
  zh: 'zh-cn',
  'en-us': 'en'
};

export function isLocale(lang, locale) {
  locale = locale.toLowerCase();
  lang = lang.toLowerCase();
  return locale === lang || map[lang] === locale;
}
